package global
{
	import flash.events.Event;
	
	import interactive.GestureManager;
	
	import lang.LanguageManager;
	
	import logics.BillManager;
	import logics.DishManager;
	import logics.LayoutManager;
	import logics.SystemManager;
	import logics.TableManager;
	
	import net.IPManager;
	import net.servers.ServerManager;
	
	import resources.ResourceManager;
	
	import ui.faces.FaceManager;
	import ui.panels.PanelManager;
	
	/**
	 *
	 * 该类负责管理其他所有Manager 
	 * @author Raykid
	 * 
	 */	
	public class Managers
	{
		public static var systemManager			: SystemManager;
		public static var ipManager				: IPManager;
		public static var languageManager		: LanguageManager;
		public static var gestureManager		: GestureManager;
		public static var serverManager			: ServerManager;
		public static var resourceManager		: ResourceManager;
		public static var tableManager			: TableManager;
		public static var layoutManager			: LayoutManager;
		public static var dishManager			: DishManager;
		public static var billManager			: BillManager;
		public static var faceManager			: FaceManager;
		public static var panelManager			: PanelManager;
		
		public function Managers()
		{
		}
		public static function init():void {
			systemManager = new SystemManager();
			ipManager = new IPManager();
			languageManager = new LanguageManager();
			gestureManager = new GestureManager();
			serverManager = new ServerManager();
			resourceManager = new ResourceManager();
			tableManager = new TableManager();
			layoutManager = new LayoutManager();
			dishManager = new DishManager();
			billManager = new BillManager();
			faceManager = new FaceManager();
			panelManager = new PanelManager();
			
			ipManager.init();
			languageManager.init();
			gestureManager.init();
			serverManager.init();
			resourceManager.init();
			panelManager.init();
			systemManager.init(serverManager);
			layoutManager.init(serverManager);
			faceManager.init(languageManager);
			
			// 连接服务器
			serverManager.ip = Global.config.Server.@ip;
			serverManager.port = int(Global.config.Server.@port);
			serverManager.addEventListener(Event.CONNECT, serverConnectHandler);
			serverManager.subscribe("ID", setIDOKHandler);
			serverManager.connect();
		}
		// 连接到服务器
		private static function serverConnectHandler(event:Event):void {
			tableManager.init(serverManager);
		}
		// 已设置完ID
		private static function setIDOKHandler(data:Object):void {
			dishManager.init(serverManager);
			billManager.init(serverManager, tableManager);
		}
	}
}